package com.igeek.compus.backend.order.controller;

import com.github.pagehelper.PageInfo;
import com.igeek.compus.backend.order.entity.Order;
import com.igeek.compus.backend.order.service.OrderService;
import com.igeek.compus.backend.product.entity.Product;
import com.igeek.compus.backend.system.Constants;
import com.igeek.compus.backend.system.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 获得订单列表
     * @param order
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public R list(Order order){

        try {
            PageInfo<Order> pageInfo = new PageInfo<>(orderService.getOrderListByPage(order));

            R r = R.success();
            r.setData(pageInfo.getList());
            r.setCount((int) pageInfo.getTotal());

            return r;
        }catch (Exception e) {
            log.error("order list异常：" + e);
            return R.fail("系统异常");
        }
    }
}
